package ThreadDemo.ThreadPoolDemo;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;


public class ExecutorTest {


    public static void main(String[] args) throws InterruptedException {

        // 利用这个方法造一个线程池
        ExecutorService executorService = Executors.newFixedThreadPool(4);



//        循环遍历来打印每一个线程
        for (int i = 0; i < 10; i++) {

//            线程开始执行
            int id = i;
            executorService.submit(()->{
                Thread t = Thread.currentThread();
                System.out.println("submit: "+ t.getName() + " 正在运行"+ id);
            });
        }




//        等待
        Thread.sleep(1000);

//        结束创建的所有线程
        executorService.shutdown();

        System.out.println("程序结束!");
    }
}
